(function($){
    function initSetState() {
        $('.delete').on('click', function(){
            var obj = $(this);
            var state = obj.attr('dstate');
            var id = obj.attr('did');
            var activity_id = obj.attr('acdid');
            var url = obj.attr('durl');
            var info = '删除';
            layer.confirm(
                '确定要【' + info + '】此活动吗？',
                {
                    icon: 3,
                    title: '系统提示',
                    btn: ['确 定', '取 消']
                },
                function(index){
                    layer.close(index);
                    layer.load();
                    $.post(
                        url,
                        {id: id, activity_id:activity_id, state: state},
                        function(data){
                            if(data.status == 10000) {
                                location.reload(true);
                            } else {
                                layer.closeAll();
                                layer.alert(data.errmsg);
                            }
                        },
                        'json'
                    );
                },
                function(index){
                    layer.close(index);
                }
            );
        });
    }
    
    $(function(){
       initSetState();
        $('#addtime').daterangepicker({
            "autoUpdateInput": false,
            "showDropdowns": true,
            "timePicker": true,
            "timePicker24Hour": true,
            "timePickerIncrement": 1,
            "autoApply": true,
            "locale": {
                "format": "YYYY-MM-DD HH:mm",
                "separator": " 至 ",
                "applyLabel": "确 定",
                "cancelLabel": "取 消",
                "fromLabel": "From",
                "toLabel": "To",
                "daysOfWeek": ["日", "一", "二", "三", "四", "五", "六"],
                "monthNames": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                "firstDay": 1
            },
            "opens": "right",
            "drops": "down",
            "buttonClasses": "btn btn-sm",
            "applyClass": "btn-success",
            "cancelClass": "btn-default"


        }, function(start, end, label) {

        });


        $('#addtime').on('apply.daterangepicker', function(ev, picker) {
            $(this).val(picker.startDate.format('YYYY-MM-DD HH:mm') + ' 至 ' + picker.endDate.format('YYYY-MM-DD HH:mm'));
        });
        $('#addtime').on('cancel.daterangepicker', function(ev, picker) {
            $(this).val('');
        });
    });
})(jQuery);